package com.gitee.deament.server.config;




import com.gitee.deament.server.core.data.DBData;
import com.gitee.deament.server.core.data.storage.impl.SystemInfoMemoryStorage;

import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

public class SystemConfig {

    public static String configFileName = "/config.properties";

    public static volatile SystemProperties SYSTEM_PROPERTIES;
    public static volatile SystemInfoMemoryStorage SYSTEM_INFO= new SystemInfoMemoryStorage();
    public static volatile DBData dbData=new DBData();
    /**
     * 系统启动的时间
     */
    public static Date startDateTime=new Date();
    static  {


        try {
            SYSTEM_PROPERTIES = new SystemProperties();

            InputStream inputStream = SystemConfig.class.getResourceAsStream(configFileName);
            Properties properties = new Properties();
            properties.load(inputStream);
            String dbnumStr = properties.getProperty("com.gitee.deament.databases", "16");
            SYSTEM_PROPERTIES.setDbnum(Integer.parseInt(dbnumStr));
            SYSTEM_PROPERTIES.setLogDir(properties.getProperty("com.gitee.deament.logdir", "classpath:/logs/"));
            SYSTEM_PROPERTIES.setPassword(properties.getProperty("com.gitee.deament.password", "admin"));
            String timeOut = properties.getProperty("com.gitee.deament.timeout", "2000");
            SYSTEM_PROPERTIES.setTimeout(Integer.parseInt(timeOut));
            String port=properties.getProperty("com.gitee.deament.port", "8888");
            SYSTEM_PROPERTIES.setPort(Integer.parseInt(port));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("loadProperties Fail");
        }

    }




}
